package cz.upce.example;

import org.jacop.constraints.Sum;
import org.jacop.constraints.XeqY;
import org.jacop.core.Domain;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
import org.jacop.search.DepthFirstSearch;
import org.jacop.search.IndomainMax;
import org.jacop.search.InputOrderSelect;
import org.jacop.search.Search;
import org.jacop.search.SelectChoicePoint;

public class MainDecide {
    public static void main(String[] args) {
        Store store = new Store();

        int pozadovanaHodnotaVykonu = 500;
        IntVar pozadovanyVykon = new IntVar(store, "SoucetVykonu", pozadovanaHodnotaVykonu, pozadovanaHodnotaVykonu);

        IntVar[] horaky = new IntVar[4];
        IntVar hUhli1 = horaky[0] = new IntVar(store, "h1", 0, 300);
        IntVar hUhli2 = horaky[1] = new IntVar(store, "h2", 0, 300);
        IntVar hPlyn3 = horaky[2] = new IntVar(store, "h3", 0, 500);
        IntVar hPlyn4 = horaky[3] = new IntVar(store, "h4", 0, 400);

        store.impose(new XeqY(hPlyn3, hPlyn4)); // musi se rovnat vykony horaku
        store.impose(new Sum(horaky, pozadovanyVykon)); //soucet  vsech musi dat nas celk. vykon

        System.out.println("store consistecy = " + store.consistency());

        Search<IntVar> label = new DepthFirstSearch<IntVar>();
        SelectChoicePoint<IntVar> select = new InputOrderSelect<IntVar>(store, horaky, new IndomainMax<IntVar>());


        boolean labeling = label.labeling(store, select);
        Domain[] solution = label.getSolution();
        System.out.println("-----------------------------------");
        for (int i = 0; i < solution.length; i++) {
            System.out.println(horaky[i].id + " - " + solution[i]);
            System.out.println(solution[i].toString());
        }
    }
}
